package com.itheima.bean;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.List;

public class Order implements Serializable {
    private String orderId;
    private User user;
    private List<Menu> menuList;
    private double totalAmount;
    private LocalDateTime createTime;

    // 添加 serialVersionUID 标记类序列化编号，可以避免再次修改类时出现的java.io.InvalidClassException
    private static final long serialVersionUID = 2L;

    public Order(String orderId, User user, List<Menu> menuList) {
        this.orderId = orderId;
        this.user = user;
        this.menuList = menuList;
        this.totalAmount =
                menuList.stream().mapToDouble(Menu::getPrice).sum();
        this.createTime = LocalDateTime.now();
    }

    public String getOrderId() {
        return orderId;
    }

    public void printMenuList() {
        for (Menu menu : this.menuList) {
            System.out.println("菜品名称：" + menu.getDishName() + "\t 价格：" + menu.getPrice());
        }

    }

    public void setOrderId(String orderId) {
        this.orderId = orderId;
    }
    public User getUser() {
        return user;
    }
    public void setUser(User user) {
        this.user = user;
    }
    public List<Menu> getMenuList() {
        return menuList;
    }
    public void setMenuList(List<Menu> menuList) {
        this.menuList = menuList;
    }
    public double getTotalAmount() {
        return totalAmount;
    }
    public void setTotalAmount(double totalAmount) {
        this.totalAmount = totalAmount;
    }
    public LocalDateTime getCreateTime() {
        return createTime;
    }
    public void setCreateTime(LocalDateTime createTime) {
        this.createTime = createTime;
    }
}

